﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BasicForms;
using System.Data.SqlClient;

namespace ReceivingDelivering.ReportGenerators
{
    public partial class FrmReportProduct : FrmSupportPrintComponents
    {
        public FrmReportProduct()
        {
            InitializeComponent();
            lbStartDate.Visible = dtNgayBatDau.Visible = lbEndDate.Visible = dtNgayKetThuc.Visible = false;
            dePrintDate.DateTime = DateTime.Now;
        }

        protected override void LoadDataReport()
        {
            base.LoadDataReport();
            var dataSouce = DB.Products.AsEnumerable().Select(
                        (p, index) => new
                        {
                            rowindex = index + 1,
                            p.ProductNo,
                            p.ProductName,
                            p.Unit,
                            p.DeliveringPrice,
                            p.ReceivingPrice,
                            p.InStockQuantity
                        });
            gridControl.DataSource = dataSouce;
            #region Định dạng bảng
            int i = 0;
            foreach (DevExpress.XtraGrid.Views.BandedGrid.BandedGridColumn col in bandedGridView1.Columns)
            {
                DevExpress.XtraGrid.Views.BandedGrid.GridBand _band = new DevExpress.XtraGrid.Views.BandedGrid.GridBand();
                col.VisibleIndex = i++;
                switch (col.FieldName)
                {
                    case "rowindex":
                        col.Width = 35;
                        col.AppearanceCell.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
                        _band.Caption = "No";
                        break;
                    case "ProductNo":
                        col.Width = 120;
                        _band.Caption = "Product No";
                        break;
                    case "ProductName":
                        col.Width = 250;
                        _band.Caption = "Product Name";
                        break;
                    case "Unit":
                        col.Width = 150;
                        _band.Caption = "Unit";
                        break;
                    case "DeliveringPrice":
                        col.Width = 120;
                        _band.Caption = "Delivering Price";
                        break;
                    case "ReceivingPrice":
                        col.Width = 120;
                        _band.Caption = "Receiving Price";
                        break;
                    case "InStockQuantity":
                        col.Width = 120;
                        _band.Caption = "InStock Quantity";
                        break;
                }
                _band.Columns.Add(col);
                bandedGridView1.Bands.Add(_band);
            }
            FormatXtraGridView(gridControl);
            DinhDangGridBandVaColumns(bandedGridView1);
            bandedGridView1.OptionsPrint.AutoWidth = true;
            bandedGridView1.BandPanelRowHeight = 30;
            FormatNumberInGridView(bandedGridView1);
            #endregion

        }
        protected override void PreviewReport()
        {
            try
            {
                PrintWithHeaderAndFooter(true, gridControl, true, true, "\nProduct detail report for current date","Print date : "+dePrintDate.DateTime.ToString("dd/MM/yyyy"), "", "","", "");
            }
            catch { }
        }
    }
}
